Get Nth catalan numberΒΆ
Write a python program for nth catalan number.
In combinatorial mathematics, the Catalan numbers form a sequence
of natural numbers that occur in various counting problems, often
involving recursively-defined objects. They are named after the Belgian
mathematician Eugene Charles Catalan (1814 - 1894).
def catalan_number(N):
if N <= 1:
return 1
res_num = 0
for i in range(N):
res_num += catalan_number(i) * catalan_number(N - i - 1)
return res_num
for n in range(10):
print(catalan_number(n))
Output:
1
1
2
5
14
42
132
429
1430
4862